﻿using Abp.Domain.Repositories;
using Abp.Domain.Services;
using shenghua.Authorization.Users;
using shenghua.Basics;
using shenghua.Basics.MemberLevels;
using shenghua.Basics.ShippingTemplates;
using shenghua.Commodity.Commodities;
using shenghua.Common.CustomValueType;
using shenghua.Member.Coupons;
using shenghua.Member.XP.Median;
using shenghua.Order.Orders.Median;
using shenghua.Member.ShippingAddresses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using shenghua.Payment.Payments;
using Abp.UI;
using static shenghua.Order.Orders.OrderShipInfo;
using shenghua.Express;
using shenghua.Member.ShoppingCart;
using Abp.Events.Bus;
using shenghua.Order.Orders.EventDatas;

namespace shenghua.Order.Orders
{
    public class OrderManager : DomainService
    {
        public IEventBus EventBus { get; set; }
        private readonly IRepository<Order> _orderRepository;
        private readonly IRepository<OrderDetail> _orderDetailRepository;
        private readonly IRepository<OrderLog> _orderLogRepository;
        private readonly SettingManager _settingManager;
        private readonly PaymentManager _paymentManager;
        private readonly WuliuManager _wuliuManager;
        private readonly OrderEvaluateManager _orderEvaluateManager;
        private readonly ShoppingCartManager _shoppingCartManager;

        public OrderManager(
            IRepository<Order> orderRepository,
            IRepository<OrderDetail> orderDetailRepository,
            IRepository<OrderLog> orderLogRepository,
            SettingManager settingManager,
            PaymentManager paymentManager,
            WuliuManager wuliuManager,
            OrderEvaluateManager orderEvaluateManager,
            ShoppingCartManager shoppingCartManager
            )
        {
            _orderRepository = orderRepository;
            _orderLogRepository = orderLogRepository;
            _settingManager = settingManager;
            _orderDetailRepository = orderDetailRepository;
            _paymentManager = paymentManager;
            _wuliuManager = wuliuManager;
            _orderEvaluateManager = orderEvaluateManager;
            _shoppingCartManager = shoppingCartManager;
            EventBus = NullEventBus.Instance;
        }

        public async Task<Order> Get(long? memberId, string orderNumber)
        {
            var query = _orderRepository.GetAll();
            if (memberId != null)
            {
                query = query.Where(r => r.MemberInfo.Id == memberId);
            }
            var item = query.Where(r => r.OrderNumber == orderNumber).FirstOrDefault();
            if(item == null)
            {
                throw new UserFriendlyException("不存在的订单");
            }
            return item;
        }

        public async Task<List<OrderDetail>> GetDetails(int orderId)
        {
            var items = await _orderDetailRepository.GetAllListAsync(r => r.OrderId == orderId);
            return items;
        }

        /// <summary>
        /// 创建订单
        /// </summary>
        public async Task<Order> CreateOrder(OrderCore orderCore, string remark = null, bool isFromShoppingCart = false)
        {
            if(!orderCore.CanSubmit)
            {
                throw new UserFriendlyException(string.Join("。", orderCore.ErrorMessages));
            }

            // 订单信息
            OrderInfo orderInfo = new OrderInfo
            {
                Subject = orderCore.Subject,
                Description = orderCore.Subject,
                CouponAmount = orderCore.CommodityCollection.CouponAmount,
                CouponId = orderCore.CommodityCollection.CouponId,
                CouponProfile = orderCore.CommodityCollection.CouponProfile,
                XPAmount = orderCore.CommodityCollection.XPAmount,
                UsedXPValue = orderCore.CommodityCollection.UsedXPValue,
                FreightAmount = orderCore.Freight,
                CommodityTotalAmount = orderCore.CommodityCollection.SumedTotalAmount,
                CommodityTotalCount = orderCore.CommodityCollection.TotalCount,
                BounsXPValue = orderCore.CommodityCollection.BounsXPValue,
                Remark = remark
            };
            OrderMemberInfo orderMemberInfo = new OrderMemberInfo
            {
                Id = orderCore.Member.Id,
                UserName = orderCore.Member.UserName
            };
            OrderShipInfo orderShipInfo = new OrderShipInfo
            {
                DeliveryAddressId = orderCore.DeliveryAddress.Id,
                ShippingTemplateId = orderCore.ShippingTemplate.Id,
                ExpressName = orderCore.ShippingTemplate.DisplayName,
                PersonName = orderCore.DeliveryAddress.PersonName,
                PhoneNumber = orderCore.DeliveryAddress.PhoneNumber,
                Province = orderCore.DeliveryAddress.Province,
                City = orderCore.DeliveryAddress.City,
                County = orderCore.DeliveryAddress.County,
                DetailedAddress = orderCore.DeliveryAddress.DetailedAddress,
                ShipStatus = OrderShipStatus.PendingShip
            };
            OrderPaymentInfo orderPaymentInfo = new OrderPaymentInfo
            {
                PaymentType = orderCore.PaymentType,
                PaymentStatus = OrderPaymentStatus.PendingPay
            };
            Order order = new Order {
                Info = orderInfo,
                MemberInfo = orderMemberInfo,
                ShipInfo = orderShipInfo,
                PaymentInfo = orderPaymentInfo
            };
            int id = _orderRepository.InsertAndGetId(order);
            // 订单明细
            List<OrderDetail> details = new List<OrderDetail>();
            InventoryDeductionType inventoryDeductionType = _settingManager.GetInventoryDeductionType();
            foreach(var item in orderCore.CommodityCollection.Items)
            {
                OrderDetail orderDetail = new OrderDetail
                {
                    OrderId = id,
                    OrderNumber = order.OrderNumber,
                    CommodityId = item.Commodity.CommodityId,
                    MemberId = orderCore.Member.Id,
                    CommodityName = item.Commodity.CommodityName,
                    Count = item.Count,
                    Price = item.Price,
                    TotalAmount = item.TotalAmount,
                    CommodityPicture = item.Picture,
                    OriginalPrice = item.OriginalPrice,
                    ShoppingOptionId = item.ShoppingOptionId,
                    XPValue = item.XPValue,
                    InventoryDeductionType = inventoryDeductionType
                };
                orderDetail.SetShoppingOptionParameters(item.ShoppingOptionParameters);
                _orderDetailRepository.Insert(orderDetail);
                details.Add(orderDetail);
            }

            // 处理购物车
            if(isFromShoppingCart)
            {
                foreach(var item in orderCore.CommodityCollection.Items)
                {
                    await _shoppingCartManager.RemoveCommodityFromShoppingCart(item.MemberId, item.CommodityId, item.ShoppingOptionId);
                }
            }

            if(orderCore.CommodityCollection.HasCoupon)
            {
                orderCore.CommodityCollection.Coupon.Status = MemberCouponStatus.Occupied;
            }

            EventBus.Trigger(new AfterGenerateOrderEventData
            {
                Order = order,
                Details = details
            });


            await Log(order.OrderNumber, "您提交的订单已经创建成功");

            return order;
        }

        /// <summary>
        /// 获取订单核心，输入商品列表，优惠券，积分，快递等才能计算，具体看参数
        /// </summary>
        /// <returns></returns>
        public async Task<OrderCore> GetOrderCore(
            Member.Members.Member member,
            List<CommodityCollectionItem> items,
            MemberShippingAddress deliveryAddress,
            ShippingTemplate shippingTemplate,
            PaymentType paymentType,
            MemberCoupon coupon = null,
            int xpValue = 0
            )
        {
            return new OrderCore(member, _settingManager, items, deliveryAddress, shippingTemplate, paymentType, coupon, xpValue);
        }

        /// <summary>
        /// 获取订单的当前物流，如果主动调用此函数会触发刷新
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public async Task<OrderShipWuliu> GetOrderWuliu(long? memberId, string orderNumber)
        {
            var item = await Get(memberId, orderNumber);
            var ship = item.ShipInfo;
            if(item.Info.Status != OrderStatus.Created || item.ShipInfo.ShipStatus != OrderShipStatus.Shipped || item.ShipInfo.WuliuType == OrderShipWuliuType.Custom)
            {
                return ship.Wuliu;
            }
            else
            {
                // 刷新物流信息
                if(DateTime.Now.AddHours(2) > ship.Wuliu.LastUpdateTime)
                {
                    // 防止用户持续刷新，默认两个小时允许刷新一次
                    if(string.IsNullOrWhiteSpace(ship.Wuliu.Number))
                    {
                        throw new UserFriendlyException("该订单未录入货运单号");
                    }

                    var queryResult = await _wuliuManager.Query(ship.Wuliu.Number, ship.Wuliu.Type);
                    if (!queryResult.Success)
                    {
                        throw new UserFriendlyException(string.Join(";", queryResult.Errors));
                    }

                    if(string.IsNullOrWhiteSpace(ship.Wuliu.Type))
                    {
                        ship.Wuliu.Type = queryResult.Type;
                    }
                    ship.Wuliu.SetItems(queryResult.Items.Select(r => new OrderShipWuliuItem
                    {
                        Time = r.Time,
                        Description = r.Description
                    }).ToList());
                    await _orderRepository.UpdateAsync(item);
                }
                return ship.Wuliu;
            }
        }

        /// <summary>
        /// 设置为发货操作，设置物流信息，主要是货运单号
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="orderNumber"></param>
        /// <param name="expressType"></param>
        /// <param name="expressName"></param>
        /// <param name="wuliuNumber"></param>
        /// <returns></returns>
        public async Task SetShipped(string orderNumber, string wuliuNumber, string expressType, string expressName)
        {
            var item = await Get(null, orderNumber);
            item.ShipInfo.ShipStatus = OrderShipStatus.Shipped;
            item.ShipInfo.WuliuType = OrderShipWuliuType.Default;
            item.ShipInfo.Wuliu.Number = wuliuNumber;
            item.ShipInfo.Wuliu.Type = expressType;
            item.ShipInfo.Wuliu.ExpressName = expressName;
            item.Info.ShipTime = DateTime.Now;
            await Log(orderNumber, $"您订单的商品已经出库，发货单号为{wuliuNumber}");
        }

        public async Task SetShipped(string orderNumber, string customWuliuInfo)
        {
            var item = await Get(null, orderNumber);
            item.ShipInfo.ShipStatus = OrderShipStatus.Shipped;
            item.ShipInfo.WuliuType = OrderShipWuliuType.Custom;
            item.ShipInfo.CustomWuliuInfo = customWuliuInfo;
            item.Info.ShipTime = DateTime.Now;
            await Log(orderNumber, $"您订单的商品已经出库");
        }

        /// <summary>
        /// 更新收货地址和运费模板，两个必须一起更新，因为互相的关联性太大
        /// </summary>
        /// <param name="order"></param>
        /// <param name="deliveryAddress"></param>
        /// <returns></returns>
        public async Task<Order> UpdateOrderDeliveryAddressAndShippingTemplate(Order order, MemberShippingAddress deliveryAddress, ShippingTemplate shippingTemplate)
        {
            if(order.PaymentInfo.PaymentStatus != OrderPaymentStatus.PendingPay || order.ShipInfo.ShipStatus != OrderShipStatus.PendingShip)
            {
                throw new UserFriendlyException("订单已经付款或已经发货，地址不可修改，如需修改请重新下单");
            }

            order.ShipInfo.PersonName = deliveryAddress.PersonName;
            order.ShipInfo.PhoneNumber = deliveryAddress.PhoneNumber;
            order.ShipInfo.Province = deliveryAddress.Province;
            order.ShipInfo.City = deliveryAddress.City;
            order.ShipInfo.County = deliveryAddress.County;
            order.ShipInfo.DetailedAddress = deliveryAddress.DetailedAddress;

            double freight = GetOrderFreightWithShippingTemplate(order, deliveryAddress, shippingTemplate);
            order.Info.FreightAmount = freight;
            order.ShipInfo.DeliveryAddressId = deliveryAddress.Id;
            order.ShipInfo.ShippingTemplateId = shippingTemplate.Id;
            
            return order;
        }

        /// <summary>
        /// 计算订单运费
        /// </summary>
        /// <param name="order"></param>
        /// <param name="deliveryAddress"></param>
        /// <param name="shippingTemplate"></param>
        /// <returns></returns>
        public double GetOrderFreightWithShippingTemplate(Order order, MemberShippingAddress deliveryAddress, ShippingTemplate shippingTemplate)
        {
            if(shippingTemplate.CanFreeShipping(deliveryAddress.AreaTag, order.Info.CommodityTotalCount, order.Info.CommodityTotalAmount))
            {
                return 0;
            }
            else
            {
                double freight = shippingTemplate.GetFreight(deliveryAddress.AreaTag, order.Info.CommodityTotalCount, order.Info.CommodityTotalAmount);
                return freight;
            }
        }

        /// <summary>
        /// 调整订单价格
        /// </summary>
        /// <param name="order"></param>
        /// <param name="adjustmentAmount"></param>
        /// <returns></returns>
        public async Task<Order> AdjustOrderAmount(Order order, double adjustmentAmount)
        {
            if(order.PaymentInfo.PaymentStatus != OrderPaymentStatus.PendingPay)
            {
                throw new UserFriendlyException("订单已付款，不可调整价格");
            }

            order.Info.AdjustmentAmount = adjustmentAmount;
            if(order.Info.TotalAmount < 0)
            {
                throw new UserFriendlyException("调整金额不合理，订单总金额低于零元");
            }
            return order;
        }

        /// <summary>
        /// 确认支付
        /// </summary>
        /// <returns></returns>
        public async Task<Order> ConfirmPayment(Order order, OrderPaymentInfo paymentInfo)
        {
            order.PaymentInfo.PaymentType = paymentInfo.PaymentType;
            order.PaymentInfo.PaymentMethod = paymentInfo.PaymentMethod;
            order.PaymentInfo.PaymentStatus = OrderPaymentStatus.Paid;
            order.PaymentInfo.TradeNumber = paymentInfo.TradeNumber;
            order.PaymentInfo.Remark = paymentInfo.Remark;
            order.Info.PaymentTime = new DateTime();

            EventBus.Trigger(new AfterPaymentOrderEventData
            {
                Order = order,
                Details = await GetDetails(order.Id)
            });

            await Log(order.OrderNumber, "付款成功");

            return order;
        }

        /// <summary>
        /// 管理员为订单做备注
        /// </summary>
        /// <param name="order"></param>
        /// <param name="adminRemark"></param>
        /// <returns></returns>
        public async Task<Order> SetAdminRemark(Order order, string adminRemark)
        {
            order.Info.AdminRemark = adminRemark;
            await _orderRepository.UpdateAsync(order);
            return order;
        }

        /// <summary>
        /// 确认收货
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public async Task ConfirmReceipt(long? memberId, string orderNumber)
        {
            var item = await Get(memberId, orderNumber);
            if(item.Info.Status != OrderStatus.Created)
            {
                throw new UserFriendlyException("错误的订单状态，无法确认收货");
            }
            if(item.ShipInfo.ShipStatus != OrderShipStatus.Shipped)
            {
                throw new UserFriendlyException("该订单商品还未发货");
            }
            item.ShipInfo.ShipStatus = OrderShipStatus.Received;
        }

        /// <summary>
        /// 订单交易完成
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public async Task FinishedOrder(long? memberId, string orderNumber)
        {
            var item = await Get(memberId, orderNumber);
            if(item.Info.Status != OrderStatus.Created)
            {
                throw new UserFriendlyException("错误的订单状态");
            }
            if(item.ShipInfo.ShipStatus != OrderShipStatus.Received)
            {
                throw new UserFriendlyException("未确认收货，无法完成订单");
            }
            if(item.PaymentInfo.PaymentStatus != OrderPaymentStatus.Paid)
            {
                throw new UserFriendlyException("未付款，无法完成订单");
            }
            item.Info.Status = OrderStatus.Succeeded;
            item.Info.FinishedTime = DateTime.Now;

            EventBus.Trigger(new AfterFinishOrderEventData
            {
                Order = item,
                Details = await GetDetails(item.Id)
            });

            await Log(orderNumber, "交易已完成，感谢您的购买，欢迎您再次光临！");
        }

        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public async Task CancelOrder(long? memberId, string orderNumber, string remark = null)
        {
            var item = await Get(memberId, orderNumber);
            await CancelOrder(item, remark);
        }
        public async Task CancelOrder(Order item, string remark = null)
        {
            if (item.Info.Status != OrderStatus.Created)
            {
                throw new UserFriendlyException("该订单无法关闭");
            }
            if (item.PaymentInfo.PaymentStatus != OrderPaymentStatus.PendingPay)
            {
                throw new UserFriendlyException("该订单无法关闭");
            }
            if (item.ShipInfo.ShipStatus != OrderShipStatus.PendingShip)
            {
                throw new UserFriendlyException("该订单无法关闭");
            }

            item.Info.Status = OrderStatus.Closed;

            EventBus.Trigger(new AfterCancelOrderEventData
            {
                Order = item,
                Details = await GetDetails(item.Id)
            });

            await Log(item.OrderNumber, remark == null ? "您取消了该订单" : remark);
        }

        /// <summary>
        /// 删除订单
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public async Task DeleteOrder(long? memberId, string orderNumber)
        {
            var item = await Get(memberId, orderNumber);
            if(item.Info.Status != OrderStatus.Closed)
            {
                throw new UserFriendlyException("只有关闭的订单才可以删除");
            }
            await _orderRepository.DeleteAsync(item);
            await Log(orderNumber, "您删除了该订单");
        }

        /// <summary>
        /// 生成支付页面，例如支付宝微信等
        /// </summary>
        /// <param name="orderNumber"></param>
        /// <param name="paymentMethod"></param>
        /// <returns></returns>
        public async Task<string> GeneratePaymentPage(string orderNumber, PaymentMethod paymentMethod)
        {
            var order = _orderRepository.GetAll().Where(r => r.OrderNumber == orderNumber).FirstOrDefault();
            if(order == null)
            {
                throw new UserFriendlyException("订单不存在或已失效");
            }
            if(order.Info.Status == OrderStatus.Closed)
            {
                throw new UserFriendlyException("订单已关闭");
            }
            if (order.Info.Status == OrderStatus.Succeeded)
            {
                throw new UserFriendlyException("订单已交易成功");
            }
            if (order.PaymentInfo.PaymentStatus == OrderPaymentStatus.Paid)
            {
                throw new UserFriendlyException("该订单已付款");
            }

            order.PaymentInfo.PaymentMethod = paymentMethod;

            var orderNumberRequest = $"order_number={orderNumber}";
            var result = _paymentManager.GeneratePaymentPage(new Payment.ThirdParties.PaymentPageParams
            {
                OrderNumber = order.OrderNumber,
                Subject = order.Info.Subject,
                Description = order.Info.Description,
                TotalAmount = order.Info.TotalAmount.Value,
                appendUrl = orderNumberRequest
            }, paymentMethod);
            return result;
        }

        /// <summary>
        /// 支付之后返回，调用此函数
        /// </summary>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public async Task PaymentReturn(Dictionary<string, string> request)
        {
            if (!request.ContainsKey("order_number"))
            {
                // 要提前将订单号作为参数附加到ReturnUrl中，如www.xxx.com/paymentreturn?order_number=xxxxxx
                throw new Exception("无效的参数");
            }
            string orderNumber = request["order_number"];


            Order order = _orderRepository.GetAll().Where(r => r.OrderNumber == orderNumber).FirstOrDefault();
            if (order == null)
            {
                throw new Exception("无效的订单");
            }
            if (order.PaymentInfo.PaymentStatus == OrderPaymentStatus.Paid)
            {
                //throw new Exception("该订单已付款，如重复付款，请联系商家");
                return;
            }

            if (order.PaymentInfo.PaymentMethod != null)
            {
                var result = _paymentManager.PaymentReturn(new Payment.ThirdParties.PaymentReturnParams
                {
                    Request = request
                }, (PaymentMethod)order.PaymentInfo.PaymentMethod);

                if (result.IsPaid)
                {
                    if (result.OrderNumber != order.OrderNumber)
                    {
                        throw new Exception("订单号不一致");
                    }
                    if (result.TotalAmount != order.Info.TotalAmount.Value)
                    {
                        throw new Exception("金额不一致");
                    }
                    
                    await ConfirmPayment(order, new OrderPaymentInfo
                    {
                        PaymentMethod = order.PaymentInfo.PaymentMethod,
                        PaymentType = order.PaymentInfo.PaymentType,
                        PaymentStatus = OrderPaymentStatus.Paid,
                        TradeNumber = result.TradeNumber,
                        Remark = "自动完成支付"
                    });
                }
                else
                {
                    await Log(orderNumber, "付款失败");
                }
            }

        }

        /// <summary>
        /// 支付之后返回，调用此函数
        /// </summary>
        /// <param name="orderNumber"></param>
        /// <returns></returns>
        public async Task PaymentNotify(Dictionary<string, string> request)
        {
            if (!request.ContainsKey("order_number"))
            {
                // 要提前将订单号作为参数附加到ReturnUrl中，如www.xxx.com/paymentreturn?order_number=xxxxxx
                throw new Exception("无效的参数");
            }
            string orderNumber = request["order_number"];


            Order order = _orderRepository.GetAll().Where(r => r.OrderNumber == orderNumber).FirstOrDefault();
            if (order == null)
            {
                throw new Exception("无效的订单");
            }
            if (order.PaymentInfo.PaymentStatus == OrderPaymentStatus.Paid)
            {
                //throw new Exception("该订单已付款，如重复付款，请联系商家");
                return;
            }

            if (order.PaymentInfo.PaymentMethod != null)
            {
                var result = _paymentManager.PaymentNotify(new Payment.ThirdParties.PaymentNotifyParams
                {
                    Request = request
                }, (PaymentMethod)order.PaymentInfo.PaymentMethod);

                if (result.IsPaid)
                {
                    if(result.OrderNumber != order.OrderNumber)
                    {
                        throw new Exception("订单号不一致");
                    }
                    if(result.TotalAmount != order.Info.TotalAmount.Value)
                    {
                        throw new Exception("金额不一致");
                    }

                    await ConfirmPayment(order, new OrderPaymentInfo
                    {
                        PaymentMethod = order.PaymentInfo.PaymentMethod,
                        PaymentType = order.PaymentInfo.PaymentType,
                        PaymentStatus = OrderPaymentStatus.Paid,
                        TradeNumber = result.TradeNumber,
                        Remark = "自动完成支付"
                    });
                }
                else
                {
                    await Log(orderNumber, "付款失败");
                }
            }


        }

        /// <summary>
        /// 对订单做出评价
        /// </summary>
        /// <param name="memberId"></param>
        /// <param name="orderNumber"></param>
        /// <param name="rateValue"></param>
        /// <param name="description"></param>
        /// <param name="pictures"></param>
        /// <returns></returns>
        public async Task EvaluateOrder(Member.Members.Member member, string orderNumber, double rateValue, string description, List<string> pictures)
        {
            var item = await Get(member.Id, orderNumber);
            if(item.Info.Status != OrderStatus.Succeeded)
            {
                throw new UserFriendlyException("未交易成功的订单不允许评价");
            }

            item.EvaluateInfo.RateValue = rateValue;
            item.EvaluateInfo.Description = description;
            item.EvaluateInfo.Pictures = new ValueArray<string>(pictures);
            item.EvaluateInfo.EvaluateStatus = OrderEvaluateStatus.Evaluated;
            item.EvaluateInfo.EvaluateTime = DateTime.Now;



            await _orderRepository.UpdateAsync(item);

            await _orderEvaluateManager.MemberEvaluate(member, item, new OrderEvaluate
            {
                Pictures = new ValueArray<string>(pictures),
                Content = description,
                RateValue = rateValue
            });

            await Log(orderNumber, "您对订单进行了评论");
        }

        public async Task<OrderLog> Log(string orderNumber, string description)
        {
            return await _orderLogRepository.InsertAsync(new OrderLog
            {
                OrderNumber = orderNumber,
                Description = description
            });
        }

        public async Task<List<OrderLog>> GetAllOrderLogs(long? memberId, string orderNumber)
        {
            var item = await Get(memberId, orderNumber);
            return await _orderLogRepository.GetAllListAsync(r => r.OrderNumber == orderNumber);
        }
    }
}
